//
//  PayMoneyTableViewCell.m
//  shanHaiHuiApp
//
//  Created by 小和尚 on 2018/3/10.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "PayMoneyTableViewCell.h"
@interface PayMoneyTableViewCell()<UITextFieldDelegate>

Strong UILabel * payLabel;

Strong UIView * lineView1;

Strong UILabel *memberLabel;

Strong UIView * lineView2;



Strong UIImageView * moneyImageView;
Strong UILabel * inputCashLabel;


Strong UILabel * yuanLabel;

Strong UIImageView * findImageView;


@end

@implementation PayMoneyTableViewCell

#pragma mark --- action

- (void)textFieldClick{
    
    if (_getTextFieldClick) {
        _getTextFieldClick(self,self.inputCashField);
        
    }
    
}



#pragma mark--- init

- (instancetype)initWithCellIdentifier:(NSString *)cellID{
    
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        self.selectionStyle = UITableViewCellEditingStyleNone;
        
        _payLabel = [[UILabel alloc] init];
        _payLabel.text = @"需支付金额";
        _payLabel.font = DEF_FontSize_14;
        _payLabel.textColor = getColor(textColor);
        
        _payMoneyLabel = [[UILabel alloc] init];
        _payMoneyLabel.text = @"200.00元";
        _payMoneyLabel.textColor = getColor(@"EC4350");
        _payMoneyLabel.font = DEF_FontSize_14;
        
        _lineView1 = [[UIView alloc] init];
        _lineView1.backgroundColor = getColor(dividerColor);
        
        _memberLabel = [[UILabel alloc] init];
        _memberLabel.text = @"会员卡支付";
        _memberLabel.font = DEF_FontSize_14;
        _memberLabel.textColor = getColor(textColor);
        
        _memberMoneyLabel = [[UILabel alloc] init];
        _memberMoneyLabel.text = @"100.00元";
        _memberMoneyLabel.font = DEF_FontSize_14;
        _memberMoneyLabel.textColor = getColor(textColor);
        
        _lineView2 = [[UIView alloc] init];
        _lineView2.backgroundColor = getColor(dividerColor);
        
        _needPayLabel = [[UILabel alloc] init];
        _needPayLabel.textColor =getColor(@"323232");
        _needPayLabel.font = DEF_FontSize_11;
        _needPayLabel.text = @"还需支付现金：100.00元";
        
        _moneyImageView = [UIImageView new];
        _moneyImageView.image = [UIImage imageNamed:@"zhaoling"];
        _moneyImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        _inputCashLabel = [[UILabel alloc] init];
        _inputCashLabel.textColor = getColor(textColor);
        _inputCashLabel.text = @"输入现金";
        _inputCashLabel.font = DEF_FontSize_14;
        
        _inputCashField = [[UITextField alloc] init];
        _inputCashField.keyboardType = UIKeyboardTypePhonePad;
        _inputCashField.placeholder = @"请输入现金";
        _inputCashField.textColor = getColor(@"323232");
        _inputCashField.font = DEF_FontSize_12;
        _inputCashField.delegate = self;
        _inputCashField.keyboardType = UIKeyboardTypeDecimalPad;
        _inputCashField.backgroundColor = getColor(@"F0F0F0");
        
        _inputCashField.tintColor = [UIColor blackColor];
        
        _inputCashField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, _inputCashField.frame.size.height)];
       _inputCashField.leftViewMode = UITextFieldViewModeAlways;
        
        
        
//        _inputCashField.inputView = [[UIView alloc]initWithFrame:CGRectZero];
//        [_inputCashField becomeFirstResponder];
     
        
        _inputCashField.layer.cornerRadius = 2;
        _inputCashField.layer.masksToBounds = YES;
        
        //去调用上面的代码，给这个UITextField的对象添加UIToolbar
        _inputCashField.inputAccessoryView = [self addToolbar];
        
        [_inputCashField addTarget:self action:@selector(textFieldClick) forControlEvents:UIControlEventEditingDidEnd];
        
        
        
        _yuanLabel = [[UILabel alloc] init];
        _yuanLabel.text = @"元";
        _yuanLabel.textColor  = getColor(@"323232");
        _yuanLabel.font = DEF_FontSize_14;
        
        _findImageView = [UIImageView new];
        _findImageView.image = [UIImage imageNamed:@"zhaoling"];
        _findImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        _findMoenyLabel = [[UILabel alloc] init];
        _findMoenyLabel.text = @"找零:0.00元";
        _findMoenyLabel.textColor = getColor(textColor);
        _findMoenyLabel.font = DEF_FontSize_11;
        
        [self sd_addSubviews:@[self.payLabel,self.payMoneyLabel,self.lineView1,self.memberLabel,self.memberMoneyLabel,self.lineView2,self.needPayLabel,self.moneyImageView,self.inputCashField,self.inputCashLabel,self.yuanLabel,self.findImageView,self.findMoenyLabel]];
        [self layOutFrame];
    }
    return self;
}


- (UIToolbar *)addToolbar
{
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(numberFieldCancle)];
    
    
    toolbar.items = @[space, bar];
    
    return toolbar;
}

- (void)numberFieldCancle{
    
    [self.inputCashField resignFirstResponder];
    
}

- (void)layOutFrame{
    ws(self)
    
    [self.payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(UNIT_HEIGHT(16));
        make.left.mas_equalTo(UNIT_WIDTH(14));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.payMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(UNIT_HEIGHT(16));
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.payLabel.mas_bottom).offset(UNIT_HEIGHT(10));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.memberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(14));
        make.top.mas_equalTo(weakself.lineView1.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.memberMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.top.mas_equalTo(weakself.lineView1.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];
    
    [self.lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakself.memberMoneyLabel.mas_bottom).offset(UNIT_HEIGHT(10));
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.needPayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.top.mas_equalTo(weakself.lineView2.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
        
    }];
    
    
    [self.moneyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.top.mas_equalTo(weakself.needPayLabel.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(22));
        make.width.mas_equalTo(UNIT_WIDTH(22));
    }];
    
    [self.inputCashLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.moneyImageView.mas_right).offset(UNIT_WIDTH(15));
        make.centerY.mas_equalTo(weakself.moneyImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];

    

    [self.inputCashField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakself.inputCashLabel.mas_right).offset(UNIT_WIDTH(15));
        make.centerY.mas_equalTo(weakself.moneyImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
       // make.right.mas_equalTo(weakself.yuanLabel.mas_left).offset(UNIT_WIDTH(-15));
        
        make.width.mas_equalTo(UNIT_WIDTH(150));
    }];
    
    [self.yuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       // make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.centerY.mas_equalTo(weakself.moneyImageView.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(30));
        make.left.mas_equalTo(weakself.inputCashField.mas_right).offset(UNIT_WIDTH(10));
    }];
    

    [self.findMoenyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.top.mas_equalTo(weakself.yuanLabel.mas_bottom).offset(UNIT_HEIGHT(10));
        make.height.mas_equalTo(UNIT_HEIGHT(30));
    }];

    
    [self.findImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakself.findMoenyLabel.mas_left).offset(UNIT_WIDTH(-10));
        make.centerY.mas_equalTo(weakself.findMoenyLabel.mas_centerY);
        make.height.mas_equalTo(UNIT_HEIGHT(17));
        make.width.mas_equalTo(UNIT_WIDTH(17));
    }];
}


@end
